//
//  DFMainHeadlineTableViewController.m
//  DFMessage
//
//  Created by lanou on 15/10/24.
//  Copyright (c) 2015年 lanou. All rights reserved.
//

#import "DFMainHeadlineTableViewController.h"
#import "DFHeadlineTableViewCell.h"
#import "DFHeadlineModel.h"
#import "PKRequestManager.h"
#import "DFHeadheadViewCell.h"
#import "UIImageView+WebCache.h"
#import "DFNewsVideoController.h"
#import "DFAppleVC.h"
#import "DFLiveViewVC.h"
#import "DFMobileVC.h"
#import "DFClickheadInViewViewController.h"
#import "MJRefresh.h"
#import "DFcomputerTableViewController.h"
#import "DFPicturesVC.h"
#import "ReviewsVC.h"
#import "DFClickAppleViewController.h"
#import "MJRefresh.h"
#import "FMDatabase.h"
#import "Reachability.h"

@interface DFMainHeadlineTableViewController ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>
{
    BOOL flag;
}
@property(nonatomic,strong)NSMutableArray *DataSourceArray;
@property(nonatomic,strong)NSMutableArray *dataHeadArray;
@property(nonatomic,strong)DFHeadheadViewCell *headVC;
@property(nonatomic,strong)UIScrollView *scrollView;
@property(nonatomic,strong)DFNewsVideoController *newsVC;
@property(nonatomic,strong)DFAppleVC *appleVC;
@property(nonatomic,strong)DFLiveViewVC *liveViewVC;
@property(nonatomic,strong)UIScrollView *aScrollView;
@property(nonatomic,strong)DFcomputerTableViewController *computerVC;
@property(nonatomic,strong)DFPicturesVC *pictureVC;
@property(nonatomic,strong)ReviewsVC *reVC;
@property(nonatomic,strong)UILabel *alabel;
@property(nonatomic,strong)UILabel *blabel;
@property(nonatomic,strong)UILabel *clabel;
@property(nonatomic,strong)UILabel *dlabel;
@property(nonatomic,strong)UILabel *elabel;
@property(nonatomic,strong)UILabel *flabel;
@property(nonatomic,strong)UILabel *gLabel;
@property(nonatomic,strong)UILabel *hLabel;
@property(nonatomic,strong)UILabel *iLabel;
@property(nonatomic,strong) UIButton *arrowBtn;
@property(nonatomic,strong) UIImageView *aimage;
@property(nonatomic,assign) int page;
@property(nonatomic,assign) int i;

@property(nonatomic,strong) UIImageView *view1;
@property(nonatomic,strong) UIImageView *view2;
@property(nonatomic,strong) UIImageView *view3;
@property(nonatomic,strong) UIImageView *view4;
//@property(nonatomic,strong)UIScrollView *topViewscrollview;
@property(nonatomic,strong)DFMobileVC *mobieVC;

@property(nonatomic,strong)NSMutableArray *urlArr;

@property(nonatomic, strong) FMDatabase *dataBase;
@end

@implementation DFMainHeadlineTableViewController


- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    flag = YES;
    
    _urlArr = [NSMutableArray array];
    [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(change) userInfo:nil repeats:YES];
    
    [self requestData];
    self.navigationController.navigationBar.hidden = YES;
    self.view.backgroundColor = [UIColor whiteColor];
    _i = 0;
    [self.view addSubview:self.topView];
    [self addTopScrollView];
    [self addscrollView];
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0,kScreenWidth , kScreenHeight - 64)];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    _scrollView.delegate = self;
    [self.mainTableView registerClass:[DFHeadlineTableViewCell class] forCellReuseIdentifier:@"cell"];
    self.mainTableView.rowHeight = 80;
    _alabel.backgroundColor = [UIColor whiteColor];
    
    [_scrollView addSubview:self.mainTableView];
    [_scrollView addSubview:_headVC];
    
    _newsVC  = [[DFNewsVideoController alloc]init];
    [self addChildViewController:_newsVC];
    _newsVC.view.frame = CGRectMake(kScreenWidth, 0, kScreenWidth, kScreenHeight- 64);
    [_scrollView addSubview:_newsVC.view];
    
    _appleVC = [[DFAppleVC alloc]init];
    [self addChildViewController:_appleVC];
    _appleVC.view.frame = CGRectMake(kScreenWidth*2, 0, kScreenWidth, kScreenHeight - 64);
    [_scrollView addSubview:_appleVC.view];
    
    _liveViewVC = [[DFLiveViewVC alloc]init];
    [self addChildViewController:_liveViewVC];
    _liveViewVC.view.frame = CGRectMake(kScreenWidth*3, 0, kScreenWidth, kScreenHeight - 64);
  
    [_scrollView addSubview:_liveViewVC.view];
    
    _mobieVC = [[DFMobileVC alloc]init];
    [self addChildViewController:_mobieVC];
    _mobieVC.view.frame = CGRectMake(kScreenWidth *4, 0, kScreenWidth, kScreenHeight - 64);
    [_scrollView addSubview:_mobieVC.view];

    _computerVC = [[DFcomputerTableViewController alloc]init];
    [self addChildViewController:_computerVC];
    _computerVC.view.frame = CGRectMake(kScreenWidth *5, 0, kScreenWidth, kScreenHeight - 64);
    [_scrollView addSubview:_computerVC.view];
    
    _pictureVC = [[DFPicturesVC alloc]init];
    [self addChildViewController:_pictureVC];
    _pictureVC.view.frame = CGRectMake(kScreenWidth *6, 0, kScreenWidth, kScreenHeight - 64);
    [_scrollView addSubview:_pictureVC.view];
    
    _reVC = [[ReviewsVC alloc]init];
    [self addChildViewController:_reVC];
    _reVC.view.frame = CGRectMake(kScreenWidth *7, 0, kScreenWidth, kScreenHeight - 64);
    [_scrollView addSubview:_reVC.view];
    
    
    _dataHeadArray = [NSMutableArray array];
    _DataSourceArray = [NSMutableArray array];
    
    [self requestDataWithType:0];
    
    
    _headVC = [[DFHeadheadViewCell alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 170)];
    self.mainTableView.tableHeaderView = _headVC;
 
    [_headVC.btn1 addTarget:self action:@selector(goweb1:) forControlEvents:UIControlEventTouchUpInside];
    [_headVC.btn2 addTarget:self action:@selector(goweb2:) forControlEvents:UIControlEventTouchUpInside];
    [_headVC.btn3 addTarget:self action:@selector(goweb3:) forControlEvents:UIControlEventTouchUpInside];

    self.mainTableView.header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        [self requestDataWithType:0];
    }];
    self.mainTableView.footer = [MJRefreshAutoNormalFooter footerWithRefreshingBlock:^{
        [self requestDataWithType:1];
    }];
    
    //=====
    NSString *filePath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES).firstObject stringByAppendingPathComponent:@"DFront.db"];
    _dataBase = [FMDatabase databaseWithPath:filePath];
    if ([_dataBase open]) {
        NSLog(@"首页的数据库打开成功");
        [_dataBase executeUpdate:@"CREATE TABLE FIRSTPAGE (imgsrc text,stitle text,sdate text,reviewer text,comment_num text,label text,eqaleid text)"];
    }
    else
    {
        NSLog(@"首页数据库打开失败");
    }
    FMResultSet *resultSet = [_dataBase executeQueryWithFormat:@"SELECT * FROM FIRSTPAGE"];
    while ([resultSet next]) {
        NSString *imgsrc = [resultSet stringForColumn:@"imgsrc"];
        NSString *stitle = [resultSet stringForColumn:@"stitle"];
        NSString *sdate = [resultSet stringForColumn:@"sdate"];
        NSString *reviewer = [resultSet stringForColumn:@"reviewer"];
        NSString *comment_num = [resultSet stringForColumn:@"comment_num"];
        NSString *label = [resultSet stringForColumn:@"label"];
        NSString *eqaleid = [resultSet stringForColumn:@"eqaleid"];
        DFHeadlineModel *model = [[DFHeadlineModel alloc] init];
        model.imgsrc = imgsrc;
        model.stitle = stitle;
        model.sdate = sdate;
        model.reviewer = reviewer;
        model.comment_num = comment_num;
        model.label = label;
        model.eqaleid = eqaleid;
        [_DataSourceArray addObject:model];
    }
    [resultSet close];
    //实现箭头动画 下拉跳转
    _aimage = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth - 42, 10, 24, 24)];
    _aimage.image = [UIImage imageNamed:@"wsad"];
    _aimage.layer.cornerRadius = 12;
    _aimage.layer.masksToBounds = YES;
    [self.topView addSubview:_aimage];
    _arrowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _arrowBtn.frame = CGRectMake(kScreenWidth - 50, 0, 50, 44);
    [_arrowBtn setTitle:@"" forState:UIControlStateNormal];
    [self.topView addSubview:_arrowBtn];
    [_arrowBtn addTarget:self action:@selector(rotate:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)rotate:(id)sender {
    if (flag) {
        [UIView animateWithDuration:0.5 animations:^{
            _aimage.transform = CGAffineTransformMakeRotation(M_PI);
        } completion:^(BOOL finished) {
            flag = NO;
            CGFloat ly = kScreenHeight - 44 - kScreenWidth * 3 / 4;
            _view1 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * 3 / 4, ly - 10, kScreenWidth / 4, kScreenWidth / 4)];
            _view2 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 2, ly + kScreenWidth / 4 - 15, kScreenWidth / 4, kScreenWidth / 4)];
            _view3 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth / 2, ly - kScreenWidth / 4, kScreenWidth / 4, kScreenWidth / 4)];
            _view4 = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenWidth * 3 / 4, ly + kScreenWidth / 2 - 15, kScreenWidth / 4, kScreenWidth / 4)];
            _view1.layer.cornerRadius = kScreenWidth / 8;
            _view1.layer.masksToBounds = YES;
            _view2.layer.cornerRadius = kScreenWidth / 8;
            _view2.layer.masksToBounds = YES;
            _view3.layer.cornerRadius = kScreenWidth / 8;
            _view3.layer.masksToBounds = YES;
            _view4.layer.cornerRadius = kScreenWidth / 8;
            _view4.layer.masksToBounds = YES;
            _view1.image = [UIImage imageNamed:@"a14"];
            _view2.image = [UIImage imageNamed:@"a12"];
            _view3.image = [UIImage imageNamed:@"a13"];
            _view4.image = [UIImage imageNamed:@"a11"];
            _view1.alpha = 0.0;
            _view2.alpha = 0.0;
            _view3.alpha = 0.0;
            _view4.alpha = 0.0;
            _view1.userInteractionEnabled = YES;
            _view2.userInteractionEnabled = YES;
            _view3.userInteractionEnabled = YES;
            _view4.userInteractionEnabled = YES;
            CGFloat lx = kScreenWidth / 4;
            UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn1.frame = CGRectMake(lx / 4, lx / 4, lx / 2, lx / 4);
            [btn1 setTitle:@"头条" forState:UIControlStateNormal];
            UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn2.frame = CGRectMake(lx / 4, lx / 2, lx / 2, lx / 4);
            [btn2 setTitle:@"视频" forState:UIControlStateNormal];
            UIButton *btn3 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn3.frame = CGRectMake(lx / 4, lx / 4, lx / 2, lx / 4);
            [btn3 setTitle:@"苹果" forState:UIControlStateNormal];
            UIButton *btn4 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn4.frame = CGRectMake(lx / 4, lx / 2, lx / 2, lx / 4);
            [btn4 setTitle:@"直播" forState:UIControlStateNormal];
            UIButton *btn5 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn5.frame = CGRectMake(lx / 4, lx / 4, lx / 2, lx / 4);
            [btn5 setTitle:@"手机" forState:UIControlStateNormal];
            UIButton *btn6 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn6.frame = CGRectMake(lx / 4, lx / 2, lx / 2, lx / 4);
            [btn6 setTitle:@"电脑" forState:UIControlStateNormal];
            UIButton *btn7 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn7.frame = CGRectMake(lx / 4, lx / 4, lx / 2, lx / 4);
            [btn7 setTitle:@"图赏" forState:UIControlStateNormal];
            UIButton *btn8 = [UIButton buttonWithType:UIButtonTypeCustom];
            btn8.frame = CGRectMake(lx / 4, lx / 2, lx / 2, lx / 4);
            [btn8 setTitle:@"评测" forState:UIControlStateNormal];
            [btn1 addTarget:self action:@selector(ClickHeadBtn:) forControlEvents:UIControlEventTouchUpInside];
            [btn2 addTarget:self action:@selector(ClickVidiobtn:) forControlEvents:UIControlEventTouchUpInside];
            [btn3 addTarget:self action:@selector(ClickAppleBtn:) forControlEvents:UIControlEventTouchUpInside];
            [btn4 addTarget:self action:@selector(ClickLiveTV:) forControlEvents:UIControlEventTouchUpInside];
            [btn5 addTarget:self action:@selector(ClickMobile:) forControlEvents:UIControlEventTouchUpInside];
            [btn6 addTarget:self action:@selector(Clickcomputer:) forControlEvents:UIControlEventTouchUpInside];
            [btn7 addTarget:self action:@selector(ClickPictures:) forControlEvents:UIControlEventTouchUpInside];
            [btn8 addTarget:self action:@selector(ClickReviews:) forControlEvents:UIControlEventTouchUpInside];

            [UIView animateWithDuration:0.5 animations:^{
                [self.view addSubview:_view3];
                [_view3 addSubview:btn1];
                [_view3 addSubview:btn2];
                _view3.alpha = 1.0;
            }];
            [UIView animateWithDuration:1.0 animations:^{
               
                [self.view addSubview:_view1];
                [_view1 addSubview:btn3];
                [_view1 addSubview:btn4];
                _view1.alpha = 1.0;
            }];
            [UIView animateWithDuration:1.5 animations:^{
                
                [self.view addSubview:_view2];
                [_view2 addSubview:btn5];
                [_view2 addSubview:btn6];
                _view2.alpha = 1.0;
            }];
            [UIView animateWithDuration:2.0 animations:^{
                [self.view addSubview:_view4];
                [_view4 addSubview:btn7];
                [_view4 addSubview:btn8];
                _view4.alpha = 1.0;
            }];


            
        }];
    }
    else {
        [UIView animateWithDuration:0.5 animations:^{
            _aimage.transform = CGAffineTransformMakeRotation(0);
        } completion:^(BOOL finished) {
            flag = YES;
            [_view1 removeFromSuperview];
            [_view2 removeFromSuperview];
            [_view3 removeFromSuperview];
            [_view4 removeFromSuperview];
            
        }];
    }
}




- (void)goweb1:(UIButton *)sender
{
    DFClickAppleViewController *web1 = [[DFClickAppleViewController alloc] init];
    web1.str = _urlArr[0];
    [self.navigationController pushViewController:web1 animated:YES];
}
- (void)goweb2:(UIButton *)sender
{
    DFClickAppleViewController *web2 = [[DFClickAppleViewController alloc] init];
    web2.str = _urlArr[1];
    [self.navigationController pushViewController:web2 animated:YES];
}
- (void)goweb3:(UIButton *)sender
{
    DFClickAppleViewController *web3 = [[DFClickAppleViewController alloc] init];
    web3.str = _urlArr[2];
    [self.navigationController pushViewController:web3 animated:YES];
}


- (void)change
{
    [UIView animateWithDuration:0.75 animations:^{
        if (_i == 0) {
            _headVC.scrollView.contentOffset = CGPointMake(0, 0);
            _i ++;
        }
        else if(_i == 1)
        {
            _headVC.scrollView.contentOffset = CGPointMake(kScreenWidth, 0);
            _i ++;
        }
        else if(_i == 2)
        {
            _headVC.scrollView.contentOffset = CGPointMake(kScreenWidth * 2, 0);
            _i = 0;
        }
    }];
}

//

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DFHeadlineModel *model = _DataSourceArray[indexPath.row];
   DFClickheadInViewViewController *clickVC = [[DFClickheadInViewViewController alloc]init];
    clickVC.str = model.eqaleid;
    [self.navigationController pushViewController:clickVC animated:YES];
}

//配置数据

-(void)requestDataWithType:(NSInteger)type
{
    if (type == 1) {
        _page ++;
    }
    else
    {
        _page = 1;
    }
    NSString *str1 = [NSString stringWithFormat:@"http://lib.wap.zol.com.cn/ipj/docList/?v=4.0&class_id=0&isReviewing=NO&last_time=2015-10-24%2015%3A44&page=%d&retina=1&vs=iph440",_page];
   [PKRequestManager requestWithType:GET urlString:str1 parDic:nil finish:^(NSData *data) {
      
      [_dataBase executeUpdate:@"DELETE FROM FIRSTPAGE"];
      
      NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers |NSJSONReadingMutableLeaves error:nil];
      if (type == 0) {
          [self.DataSourceArray removeAllObjects];
      }
      NSArray *listArray = dic[@"list"];
      for (NSDictionary *modelDic in listArray) {
          DFHeadlineModel *model = [[DFHeadlineModel alloc]init];
          [model setValuesForKeysWithDictionary:modelDic];
          [_DataSourceArray addObject:model];
          [_dataBase executeUpdate:@"INSERT INTO FIRSTPAGE (imgsrc,stitle,sdate,reviewer,comment_num,label,eqaleid) VALUES (?,?,?,?,?,?,?)",model.imgsrc,model.stitle,model.sdate,model.reviewer,model.comment_num,model.label,model.eqaleid];
                    }
    [self.mainTableView.header endRefreshing];
    [self.mainTableView.footer endRefreshing];
    [self.mainTableView reloadData];
   
       } error:^(NSError *error) {
      NSLog(@"%@",error);
           [self.mainTableView.header endRefreshing];
           [self.mainTableView.footer endRefreshing];
  }];
 
}

- (void)requestData
{
    [PKRequestManager requestWithType:GET urlString:@"http://lib.wap.zol.com.cn/ipj/docList/?v=4.0&class_id=0&isReviewing=NO&last_time=2015-10-24%2015%3A44&page=1&retina=1&vs=iph440" parDic:nil finish:^(NSData *data) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers |NSJSONReadingMutableLeaves error:nil];
        NSArray *listArray1 = dic[@"pics"];
        for (int i = 0 ; i<3; i++) {
            [_headVC.scrollView.subviews[i*2] sd_setImageWithURL:[listArray1[i] objectForKey:@"imgsrc"]];
            ((UILabel *)_headVC.scrollView.subviews[2*i+1]).text = [listArray1[i] objectForKey:@"stitle"];
            
            NSString *string = [listArray1[i] objectForKey:@"url"];
            [_urlArr addObject:string];
        }
    } error:^(NSError *error) {
        NSLog(@"%@",error);
    }];

}


-(void)addscrollView{
    _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, kScreenWidth, kScreenHeight - 64)];
    _scrollView.contentSize = CGSizeMake(kScreenWidth *8, 0);
    _scrollView.bounces = NO;
  _scrollView.pagingEnabled = YES;
    
    [self.view addSubview:_scrollView];
}


-(void)addTopScrollView{
    
    _aScrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(5, 7, (kScreenWidth-70), 33)];
    //_aScrolflView.backgroundColor = [UIColor redColor];
    _aScrollView.showsHorizontalScrollIndicator = NO;
    [self.topView addSubview:_aScrollView];
    _aScrollView.contentSize = CGSizeMake(kScreenWidth *2 - 100, 30);
    
    UIButton *HeadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    HeadBtn.frame = CGRectMake(0, 0, kScreenWidth / 8, 30);
    _alabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, kScreenWidth / 8, 2)];
    [_aScrollView addSubview:_alabel];
    HeadBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [HeadBtn setTitle:@"头条" forState:UIControlStateNormal];
    [HeadBtn addTarget:self action:@selector(ClickHeadBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    [_aScrollView addSubview:HeadBtn];
    
    UIButton *VidioBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [VidioBtn addTarget:self action:@selector(ClickVidiobtn:) forControlEvents:(UIControlEventTouchUpInside)];
    VidioBtn.frame = CGRectMake(kScreenWidth / 4 - 10, 0, kScreenWidth/8, 30);
    _blabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth / 4 - 10, 30, kScreenWidth/8, 2)];
    [_aScrollView addSubview:_blabel];
    VidioBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [VidioBtn setTitle:@"视频" forState:(UIControlStateNormal)];
    [_aScrollView addSubview:VidioBtn];
    
    UIButton *appleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    appleBtn.frame = CGRectMake(2*(kScreenWidth / 4) - 20, 0, kScreenWidth/8, 30);
    [appleBtn addTarget:self action:@selector(ClickAppleBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    _clabel = [[UILabel alloc]initWithFrame:CGRectMake(2*(kScreenWidth / 4) - 20, 30,kScreenWidth/8 , 2)];
    [_aScrollView addSubview:_clabel];
    appleBtn.titleLabel.font = [UIFont systemFontOfSize:16];
    [appleBtn setTitle:@"苹果" forState:UIControlStateNormal];
    [_aScrollView addSubview:appleBtn];
    [_aScrollView addSubview:_clabel];
    
    UIButton *LiveTVvc = [UIButton buttonWithType:UIButtonTypeCustom];
    [LiveTVvc addTarget:self action:@selector(ClickLiveTV:) forControlEvents:(UIControlEventTouchUpInside)];
    LiveTVvc.titleLabel.font = [UIFont systemFontOfSize:16];
    [LiveTVvc setTitle:@"直播" forState:UIControlStateNormal];
    LiveTVvc.frame = CGRectMake(3 * (kScreenWidth / 4) - 30, 0, kScreenWidth/8, 30);
    [_aScrollView addSubview:LiveTVvc];
    
    _dlabel = [[UILabel alloc]initWithFrame:CGRectMake(3 * (kScreenWidth / 4) - 30, 30, kScreenWidth/8, 2)];
    [_aScrollView addSubview:_dlabel];

    UIButton *MobileVC = [UIButton buttonWithType:UIButtonTypeCustom];
    [MobileVC addTarget:self action:@selector(ClickMobile:) forControlEvents:(UIControlEventTouchUpInside)];
    MobileVC.titleLabel.font = [UIFont systemFontOfSize:15];
    MobileVC.frame = CGRectMake(4 *(kScreenWidth /4) - 40, 0, kScreenWidth/8, 30);
    [MobileVC setTitle:@"手机" forState:UIControlStateNormal];
    _elabel = [[UILabel alloc]initWithFrame:CGRectMake(4 *(kScreenWidth /4) - 40, 30, kScreenWidth/8, 2)];
    [_aScrollView addSubview:_elabel];
    [_aScrollView addSubview:MobileVC];
    
    UIButton *computerVC = [UIButton buttonWithType:UIButtonTypeCustom];
    computerVC.titleLabel.font = [UIFont systemFontOfSize:16];
    [computerVC addTarget:self action:@selector(Clickcomputer:) forControlEvents:(UIControlEventTouchUpInside)];
    computerVC.frame = CGRectMake(5*(kScreenWidth /4) - 50,0, kScreenWidth/8, 30);
    [computerVC setTitle:@"电脑" forState:UIControlStateNormal];
    _flabel = [[UILabel alloc]initWithFrame:CGRectMake(5*(kScreenWidth /4) - 50, 30, kScreenWidth/8, 2)];
    [_aScrollView addSubview:_flabel];
    

    [_aScrollView addSubview:computerVC];
   
    UIButton *PicturesVC = [UIButton buttonWithType:UIButtonTypeCustom];
    [PicturesVC addTarget:self action:@selector(ClickPictures:) forControlEvents:(UIControlEventTouchUpInside)];
    PicturesVC.frame = CGRectMake(6*(kScreenWidth/4) - 60, 0, kScreenWidth/8, 30);
    PicturesVC.titleLabel.font = [UIFont systemFontOfSize:15];
    _gLabel = [[UILabel alloc]initWithFrame:CGRectMake(6*(kScreenWidth/4) - 60, 30,kScreenWidth/8 , 2)];
    [_aScrollView addSubview:_gLabel];
  
    [PicturesVC setTitle:@"图赏" forState:UIControlStateNormal];
    [_aScrollView addSubview:PicturesVC];
    
    UIButton *ReviewsVC = [UIButton buttonWithType:UIButtonTypeCustom];
    [ReviewsVC addTarget:self action:@selector(ClickReviews:) forControlEvents:(UIControlEventTouchUpInside)];
    ReviewsVC.frame = CGRectMake(7*(kScreenWidth/4) - 70, 0, kScreenWidth/8, 30);
    [ReviewsVC setTitle:@"评测" forState:UIControlStateNormal];
    ReviewsVC.titleLabel.font = [UIFont systemFontOfSize:16];
    _hLabel = [[UILabel alloc]initWithFrame:CGRectMake(7*(kScreenWidth/4) - 70, 30, kScreenWidth/8, 2)];
    [_aScrollView addSubview:_hLabel];
    [_aScrollView addSubview:ReviewsVC];
    
//    UIButton *authorbtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    authorbtn.frame = CGRectMake(8 * (kScreenWidth / 4) - 80, 0, 80, 30);
//    [authorbtn setTitle:@"App研发" forState:UIControlStateNormal];
//    authorbtn.titleLabel.font = [UIFont systemFontOfSize:16];
//    [authorbtn addTarget:self action:@selector(authorshow:) forControlEvents:UIControlEventTouchUpInside];
//    _iLabel = [[UILabel alloc] initWithFrame:CGRectMake(8 * (kScreenWidth / 4) - 80, 30, 80, 2)];
//    [_aScrollView addSubview:authorbtn];
//    [_aScrollView addSubview:_iLabel];
}
//0 0
//- (void)authorshow:(UIButton *)sender
//{
//    UIAlertController *alertController2 = [UIAlertController alertControllerWithTitle:@"＝＝＝＝＝＝版权所有＝＝＝＝＝＝"message:@"APP黑人开发组成员" preferredStyle:UIAlertControllerStyleActionSheet];
//    UIAlertAction *cancelAction2 = [UIAlertAction actionWithTitle:@"----许增辉----" style:(UIAlertActionStyleDefault) handler:nil];
//    UIAlertAction *okAction2 = [UIAlertAction actionWithTitle:@"----王腾飞----" style:(UIAlertActionStyleDefault) handler:nil];
//    UIAlertAction *deleateAction2 = [UIAlertAction actionWithTitle:@"----吴义英----" style: (UIAlertActionStyleDefault) handler:nil];
//    UIAlertAction *okAction3 = [UIAlertAction actionWithTitle:@"版本号1.01盗版必究" style:(UIAlertActionStyleDestructive) handler:nil];
//    UIAlertAction *deleateAction3 = [UIAlertAction actionWithTitle:@"返回" style: (UIAlertActionStyleDefault) handler:nil];
//    
//    [alertController2 addAction:cancelAction2];
//    [alertController2 addAction:okAction2];
//    [alertController2 addAction:deleateAction2];
//    [alertController2 addAction:okAction3];
//    [alertController2 addAction:deleateAction3];
//    [self presentViewController:alertController2 animated:YES completion:nil];
//}



//资讯
-(void)ClickHeadBtn:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(0, 0);
    _aScrollView.contentOffset = CGPointMake(0, 0);
    _alabel.backgroundColor = [UIColor whiteColor];
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

}

//视频

-(void)ClickVidiobtn:(UIButton *)sender{
    
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth, 0);
    _aScrollView.contentOffset = CGPointMake(0, 0);
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _blabel.backgroundColor = [UIColor whiteColor];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

}


//苹果


-(void)ClickAppleBtn:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth *2, 0);
    _aScrollView.contentOffset = CGPointMake(kScreenWidth / 8, 0);
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor whiteColor];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}


//直播

-(void)ClickLiveTV:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth *3, 0);
    
    _aScrollView.contentOffset = CGPointMake((kScreenWidth / 8) * 2, 0);

    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor whiteColor];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}

//手机

-(void)ClickMobile:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth *4, 0);
    
    _aScrollView.contentOffset = CGPointMake((kScreenWidth / 8) * 4, 0);
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor whiteColor];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
}



//电脑
-(void)Clickcomputer:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth *5, 0);
    _aScrollView.contentOffset = CGPointMake((kScreenWidth / 8) * 6, 0);
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor whiteColor];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    


}



//图赏

-(void)ClickPictures:(UIButton *)sender{
    
    _scrollView.contentOffset = CGPointMake(kScreenWidth *6, 0);
    _aScrollView.contentOffset = CGPointMake((kScreenWidth / 8) * 8, 0);
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor whiteColor];
    _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    

    
}



//评测
-(void)ClickReviews:(UIButton *)sender{
    _scrollView.contentOffset = CGPointMake(kScreenWidth *7, 0);
    _aScrollView.contentOffset = CGPointMake((kScreenWidth / 8) * 8, 0);
    _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
    _hLabel.backgroundColor = [UIColor whiteColor];

}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    if (_scrollView.contentOffset.x/kScreenWidth ==0) {
        
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor whiteColor];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

    }
    else if(_scrollView.contentOffset.x/kScreenWidth == 1){
        
        _blabel.backgroundColor = [UIColor whiteColor];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
 
    }else if(_scrollView.contentOffset.x/kScreenWidth == 2)
    {
        _aScrollView.contentOffset = CGPointMake(0, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor whiteColor];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        

    }else if(_scrollView.contentOffset.x/kScreenWidth == 3)
    {
        _aScrollView.contentOffset = CGPointMake(kScreenWidth - 150, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor whiteColor];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        
        
    } else if(_scrollView.contentOffset.x/kScreenWidth == 4){
        _aScrollView.contentOffset = CGPointMake(kScreenWidth - 150, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor whiteColor];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

        
    }else if(_scrollView.contentOffset.x/kScreenWidth == 5){
        _aScrollView.contentOffset = CGPointMake(kScreenWidth - 100, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor whiteColor];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

        
    }else if(_scrollView.contentOffset.x/kScreenWidth == 6){
        _aScrollView.contentOffset = CGPointMake(kScreenWidth - 50, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor whiteColor];
        _hLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];

        
        
    }else if(_scrollView.contentOffset.x/kScreenWidth ==7){
        _aScrollView.contentOffset = CGPointMake(kScreenWidth, 0);
        _blabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _alabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _clabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _dlabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _elabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _flabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _gLabel.backgroundColor = [UIColor colorWithRed:0.875 green:0.173 blue:0.043 alpha:1.000];
        _hLabel.backgroundColor = [UIColor whiteColor];

        
    }
    
    
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    // Return the number of sections.
    return 1;
}





- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return _DataSourceArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    DFHeadlineTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    
    
    cell.configureModel = _DataSourceArray[indexPath.row];
        
    // Configure the cell...
    
    return cell;
}



@end
